package br.com.knowledge.persistence.hibernate.dao;

import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.Query;
import static org.hibernate.criterion.Example.create;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;

import br.com.knowledge.persistence.hibernate.entities.AbfMetodoobjetocoluna;
import br.com.knowledge.persistence.hibernate.entities.CadProjeto;
import br.com.knowledge.persistence.hibernate.entities.CadUsuarioprojeto;

/**
 * A data access object (DAO) providing persistence and search support for
 * CadUsuarioprojeto entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see br.com.knowledge.persistence.hibernate.entities.CadUsuarioprojeto
 * @author MyEclipse Persistence Tools
 */

public class AbfMetodoobjetocolunaDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(AbfMetodoobjetocolunaDAO.class);
	// property constants
	public static final String ACAO = "acao";

	public void save(AbfMetodoobjetocoluna transientInstance) {
		log.debug("saving CadUsuarioprojeto instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(AbfMetodoobjetocoluna persistentInstance) {
		log.debug("deleting AbfMetodoobjetocoluna instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public AbfMetodoobjetocoluna findById(java.lang.Integer id) {
		log.debug("getting AbfMetodoobjetocoluna instance with id: " + id);
		try {
			AbfMetodoobjetocoluna instance = (AbfMetodoobjetocoluna) getSession()
					.get( "br.com.knowledge.persistence.hibernate.entities.AbfMetodoobjetocoluna", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}	


/*	
	public AbfMetodoobjetocoluna findByUsuarioProjeto(java.lang.Integer cadUsuarioId, java.lang.Integer cadProjetoId) {
		log.debug("getting AbfMetodoobjetocoluna instance with cadUsuarioId: " + cadUsuarioId);
		log.debug("getting AbfMetodoobjetocoluna instance with cadProjetoId: " + cadProjetoId);
		try {
			String queryString = "from AbfMetodoobjetocoluna where cad_projeto_id = "+ cadProjetoId + " and "
								+ "cad_usuario_id = " + cadUsuarioId;
			Query queryObject = getSession().createQuery(queryString);
			return (AbfMetodoobjetocoluna) queryObject.uniqueResult();
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}	*/	
	
	
	
	public List<AbfMetodoobjetocoluna> findByExample(AbfMetodoobjetocoluna instance) {
		log.debug("finding AbfMetodoobjetocoluna instance by example");
		try {
			List<AbfMetodoobjetocoluna> results = (List<AbfMetodoobjetocoluna>) getSession()
					.createCriteria( "br.com.knowledge.persistence.hibernate.entities.AbfMetodoobjetocoluna")
					.add(create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding AbfMetodoobjetocoluna instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from AbfMetodoobjetocoluna as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<AbfMetodoobjetocoluna> findByPathusuario(Object pathusuario) {
		return findByProperty(ACAO, pathusuario);
	}

	public List findAll() {
		log.debug("finding all AbfMetodoobjetocoluna instances");
		try {
			String queryString = "from AbfMetodoobjetocoluna";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public AbfMetodoobjetocoluna merge(AbfMetodoobjetocoluna detachedInstance) {
		log.debug("merging AbfMetodoobjetocoluna instance");
		try {
			AbfMetodoobjetocoluna result = (AbfMetodoobjetocoluna) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(AbfMetodoobjetocoluna instance) {
		log.debug("attaching dirty AbfMetodoobjetocoluna instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(AbfMetodoobjetocoluna instance) {
		log.debug("attaching clean AbfMetodoobjetocoluna instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}